<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8" name="viewport" content="initial-scale=1.0, user-scalable=no">
<title>后台管理</title>
<link rel="shortcut icon" href="static/image/logo01.ico"/>
<link href="static/easyui/themes/default/easyui.css" rel="stylesheet" />
<link href="static/easyui/themes/icon.css" rel="stylesheet" />
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui-lang-zh_CN.js"></script>
</head>
<body>
	<table id="dg" class="easyui-datagrid" data-options="toolbar:'#tb'"></table>
	<script type="text/javascript">
	$(function() {
		$('#dg').datagrid({
			nowrap: false,
			pagination:true,
			pageList:[2,5,10,20,30],
			pageSize:5,
			url: "user/page",
			showHeader: true,
			columns: [[
				{field:'username',title:'用户名',width:150},
				{field:'age',title:'年龄',width:100},
				{field:'phone',title:'手机号',width:100},
				{field:'address',title:'地址',width:200},
				{field:'gender',title:'性别',width:200},
				{field:'email',title:'邮箱',width:200},
				{field: 'option', title: '操作', width: 200, formatter: function(value,row,index) {
					return "<button onclick='removeUser("+row.id+")'>删除</button>&emsp;"
                    +"<button onclick='editUser("+row.id+")'>修改</button>"
				}}
			]]
		});
	});
	
	function removeUser(id) {
		$.messager.confirm('提示', '确认删除？', function(r){
			if (r){
				$.ajax({
					url: "user/delete",
					type: "post",
					data: {"id": id},
					success: function(response) {
						$.messager.alert('提示信息', response.message, 'info', function() {
							$('#dg').datagrid('load');
						})
					}
				})
			}
		});
	}
	function editUser(id) {
		openTopWindow({
			title: "编辑用户信息",
			url: "manage/admin/editUser.jsp?id="+id,
			callback: function() {
				$('#dg').datagrid('load');
			}
		})
	}
	/* 在父窗口中打开window */
   	function openTopWindow(options) {
		options = !options ? {} : options;
		options.width = !options.width ? 500 : options.width;
		options.height = !options.height ? 400 : options.height;
		options.url = !options.url ? "404.html" : options.url;
		options.title = !options.title ? "" : options.title;
		parent.$("#topWindow").window({
			title : options.title,
			width : options.width,
			height : options.height,
			content : "<iframe scrolling='no' frameborder='0' border='0' height='100%' width='100%' src='"
					+ options.url + "'></iframe>",
			modal : true,
			resizable : false,
			collapsible : false,
			// 关闭窗口的回调函数
			onClose: options.callback
		});
	}
	</script>
</body>
</html>